
Declarations

* Variables

Values can be assigned to variables. 

Vars can then be used in expressions to stand for their value.  

Variables in ML DO NOT VARY!

** Type bindings

Also type binding

  type real = float
  type count = int and average = real

** Value bindings

let m = 3 + 2
let m : int = 3 + 2

let pi : float = 3.14 and e : real = 2.17

let x : float = sin pi

*** Substitution principle

To evaluate "cos x", replace x by its value, then compute as before

val m : int = 3 + 2
val n : int = m * m 

Binding is not assignment!  But you can SHADOW a binding

val n : float = 3.4 

Different type, different value

** Limiting scope

let x = 5 in
  x + x


let m : int = 2
let r : int =
  (let m : int = 3 in
   let n : int = m * m in
    m * n) * m 

** Typing and Evaluation

1) Type checking must take account of the declared type of a variable
2) Evaluation must take account of the declared value of a variable

*** Environments
 
Used for type checking and evaluation
 - Type environment
 - Value environment    

Declarations:

  val m : int = 0
  val x : real = Math.sqrt(2.0)
  val c : char = #"a"

Type env:

  val m : int
  val x : real
  val c : char

Value env:

  val m = 0
  val x = 1.414
  val c = #"a"


Extend typing rules

typeenv |- exp : typ

valenv |- exp --> val
